/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 * Description: GPU/NPU send/recv window memory manager
 */
#ifndef HCCL_TYPICAL_WINDOW_MEM_H
#define HCCL_TYPICAL_WINDOW_MEM_H

#include <mutex>
#include <map>
#include "hccl_common.h"

namespace hccl {
class TypicalWindowMem {
public:
    static TypicalWindowMem &GetInstance();

    // Alloc and free window memory
    HcclResult AllocWindowMem(void **ptr, size_t size);
    HcclResult FreeWindowMem(void *ptr);

private:
    TypicalWindowMem();
    ~TypicalWindowMem();
    // Delete copy and move constructors and assign operators
    TypicalWindowMem(TypicalWindowMem const&) = delete;             // Copy construct
    TypicalWindowMem(TypicalWindowMem&&) = delete;                  // Move construct
    TypicalWindowMem& operator=(TypicalWindowMem const&) = delete;  // Copy assign
    TypicalWindowMem& operator=(TypicalWindowMem &&) = delete;      // Move assign

    HcclResult FreeAllWinowMem();

    std::mutex windowMemMapMutex_;
    std::map<uint64_t, uint64_t> windowMemMap_;                     // allocated window mem map
};
}  // namespace hccl
#endif  // HCCL_TYPICAL_WINDOW_MEM_H